package com.study.servlet.servletcontext;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* @Name: GetServletContextDemo01
* @Description: 使用ServletContext获取web应用初始化全局参数
* @Author: 李超	lc_jack@foxmail.com
* @CreateDate: 2017-3-1 上午9:24:04 
* @Version: V1.0
 */
public class GetServletContextDemo01 extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		ServletContext context = this.getServletContext() ;
		Enumeration<String> params = context.getInitParameterNames() ;
		while(params.hasMoreElements()) {
			String paramName = params.nextElement() ;
			String paramValue = context.getInitParameter(paramName) ;
			System.out.println(paramName + ":" + paramValue) ;
			response.getWriter().write(paramName + ":" + paramValue + "\n") ;
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doGet(request, response);
	}

}
